package com.ruoyi.workbench.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.workbench.domain.WorkSpecializedClassManage;
import com.ruoyi.workbench.service.IWorkSpecializedClassManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 专班管理Controller
 * 
 * @author ruoyi
 * @date 2024-07-02
 */
@RestController
@RequestMapping("/jobAid/classManage")
public class WorkSpecializedClassManageController extends BaseController
{
    @Autowired
    private IWorkSpecializedClassManageService workSpecializedClassManageService;

    /**
     * 查询专班管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WorkSpecializedClassManage workSpecializedClassManage)
    {
        startPage();
        List<WorkSpecializedClassManage> list = workSpecializedClassManageService.selectWorkSpecializedClassManageList(workSpecializedClassManage);
        return getDataTable(list);
    }

    /**
     * 导出专班管理列表
     */
    @Log(title = "专班管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkSpecializedClassManage workSpecializedClassManage)
    {
        List<WorkSpecializedClassManage> list = workSpecializedClassManageService.selectWorkSpecializedClassManageList(workSpecializedClassManage);
        ExcelUtil<WorkSpecializedClassManage> util = new ExcelUtil<WorkSpecializedClassManage>(WorkSpecializedClassManage.class);
        util.exportExcel(response, list, "专班管理数据");
    }

    /**
     * 获取专班管理详细信息
     */
    @GetMapping(value = "/{sid}")
    public AjaxResult getInfo(@PathVariable("sid") Integer sid)
    {
        return success(workSpecializedClassManageService.selectWorkSpecializedClassManageBySid(sid));
    }

    /**
     * 新增专班管理
     */
    @Log(title = "专班管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkSpecializedClassManage workSpecializedClassManage)
    {
        return toAjax(workSpecializedClassManageService.insertWorkSpecializedClassManage(workSpecializedClassManage));
    }

    /**
     * 修改专班管理
     */
    @Log(title = "专班管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkSpecializedClassManage workSpecializedClassManage)
    {
        return toAjax(workSpecializedClassManageService.updateWorkSpecializedClassManage(workSpecializedClassManage));
    }

    /**
     * 删除专班管理
     */
    @Log(title = "专班管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sids}")
    public AjaxResult remove(@PathVariable Integer[] sids)
    {
        return toAjax(workSpecializedClassManageService.deleteWorkSpecializedClassManageBySids(sids));
    }

    @GetMapping("/getUsers")
    public AjaxResult getUsers(){
        return success(workSpecializedClassManageService.getUser());
    }

    @GetMapping("/getDeptAndPostByUserId")
    public AjaxResult getUsers(@RequestParam("userId") Long userId){
        WorkSpecializedClassManage workSpecializedClassManage = workSpecializedClassManageService.getDeptAndPostByUserId(userId);
        return success(workSpecializedClassManage);
    }


}
